package edu.mis.modules.room;

import com.jfinal.plugin.activerecord.Record;
import edu.mis.model.Room;

import java.util.List;

/**
 * 商品服务类
 *
 */
public class RoomService {
	
	/**
	 * 添加商品
	 * @param room
	 * @return
	 */
	public boolean addRoom(Room room){
		if(room.findRoomByName(room.getRoomNumber())==null){ //此处为业务逻辑，写在service里，不要写在model里。判断是否商品名重复，
			return room.save();
		}else{
			return false;
		}
		
	}
    /**
     * 修改商品信息
     * @param room
     * @return
     */
    public boolean updateRoom(Room room){
            return room.update();
    }
	
	/**
	 * 修改商品数量
	 * @param newRoomQty
	 * @return
	 */

	

	
	/**
	 * 根据ID得到商品
	 * @param id
	 * @return
	 */
	public Room findRoomById(int id) {
		return Room.dao.findById(id);
	}
	
	/**
	 * 查询所有商品
	 * @return
	 */
	public List<Room> findAllRoom(){
		return Room.dao.findAll();
	}
	/**
	 * 查询所有商品及其权限
	 * @return
	 */
	public List<Record> findAllRoomWithRoomTypeAndStatus(){
		return Room.dao.findAllRecord();
	}
	public List<Record> findRoomWithTypeAndStatus(Integer roomTtypeId, Integer roomStatusId){
		return Room.dao.findRoomWithTypeAndStatus(roomTtypeId, roomStatusId);
	}

	/**
	 * 商品分类
	 * @param id
	 * @param typeId
	 * @return
	 */
	public boolean classifyRoom(int id, int typeId) {
		Room room = findRoomById(id);
		room.setRoomTypeId(typeId);
		return room.update();
	}
	/**
	 * 删除商品
	 * @param id
	 * @return
	 */
	public boolean deleteRoomById(int id) {
		return Room.dao.deleteById(id);
	}
}
